public class demo4 {
    private static volatile int sum;
    public static void main(String[] args) throws InterruptedException {
        Object lock =new Object();
        Thread t1=new Thread(()->{
                for (int i = 1; i <= 10; i++)
                    sum+=i;

        });
        Thread t2=new Thread(()->{
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            for (int i = 11; i <= 20; i++)
                sum+=i;

        });
        Thread t3=new Thread(()->{
            for (int i = 21; i <= 30; i++)
                sum+=i;
        });
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        System.out.println(sum);
    }
}
